package com.md.api.common.utils;

import java.io.*;

public class SerializeUtils {

	public static String serializeToString(Object obj) throws IOException {
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
		ObjectOutputStream objOut = new ObjectOutputStream(byteOut);
		objOut.writeObject(obj);
		return byteOut.toString("ISO-8859-1");// 此处只能是ISO-8859-1,但是不会影响中文使用
	}

	// 反序列化
	public static Object deserializeToObject(String str) throws IOException, ClassNotFoundException {
		ByteArrayInputStream byteIn = new ByteArrayInputStream(
				str.getBytes("ISO-8859-1"));
		ObjectInputStream objIn = new ObjectInputStream(byteIn);
		return objIn.readObject();
	}

}
